package com.ctshk.rpc.hotel.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.hotel.dto.HotelListManagerDTO;
import com.ctshk.rpc.hotel.dto.HotelQueryDTO;
import com.ctshk.rpc.hotel.entity.Hotel;
import com.ctshk.rpc.hotel.req.HotelListManagerReq;
import com.ctshk.rpc.hotel.req.HotelQueryReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 酒店资源 Mapper 接口
 * </p>
 *
 * @author yinhuan
 * @since 2021-03-03
 */
public interface HotelMapper extends BaseMapper<Hotel> {

    /**
     * 酒店查询列表
     *
     * @param req 入参
     * @return
     */
    @Select("<script>"+"SELECT\n" +
            "\tt_hotel.id,\n" +
            "\tt_hotel.city_name,\n" +
            "\tt_hotel.name as hotelName,\n" +
            "\tt_hotel_room_type.NAME as roomName,\n" +
            "\tt_hotel_product.NAME as productName,\n" +
            "\tt_hotel_room_type.bed_type,\n" +
            "\tt_hotel_product.has_breakfast as breakfast,\n" +
            "\tt_hotel.source_type as sourceType,\n" +
            "\tt_hotel_product.supplier_name,\n" +
            "\tt_hotel_product.target_population,\n" +
            "\tt_hotel_product.charge_user as chargerUser,\n" +
            "\tt_hotel_product.STATUS as saleStatus,\n" +
            "\tt_hotel_product.allow_package as allowPackage, \n" +
            "\tt_hotel_product.approval_status as approveStatus \n" +
            "FROM\n" +
            "\tt_hotel,\n" +
            "\tt_hotel_room_type,\n" +
            "\tt_hotel_product\n" +
            "where\n" +
            "\tt_hotel.id = t_hotel_room_type.hotel_id \n" +
            "and \n" +
            "  t_hotel.id = t_hotel_product.hotel_id\n" +
            "and\n" +
            "\tt_hotel_room_type.id = t_hotel_product.room_id\n" +
            "and 1=1"+
            "<if test=\"req.cityName != null and req.cityName != ''\"> and (t_hotel.city_name LIKE CONCAT('%',#{req.cityName},'%'))</if> \n"+
            "<if test=\"req.brandName != null and req.brandName != ''\"> and (t_hotel.brand_name LIKE CONCAT('%',#{req.brandName},'%'))</if> \n"+
            "<if test=\"req.hotelName != null and req.hotelName != ''\"> and (t_hotel.name LIKE CONCAT('%',#{req.hotelName},'%'))</if> \n"+
            "<if test=\"req.roomName != null and req.roomName != ''\"> and (t_hotel_room_type.name LIKE CONCAT('%',#{req.roomName},'%'))</if> \n"+
            "<if test=\"req.supplierName != null and req.supplierName != ''\"> and (t_hotel_product.supplier_name LIKE CONCAT('%',#{req.supplierName},'%'))</if> \n"+
            "<if test=\"req.sourceType != null and req.sourceType != ''\"> and t_hotel_product.source_type = #{req.sourceType}</if> \n"+
            "<if test=\"req.saleStatus != null and req.saleStatus != ''\"> and t_hotel_product.status = #{req.saleStatus}</if> \n"+
            "<if test=\"req.allowPackage != null and req.allowPackage != ''\"> and t_hotel_product.allow_package = #{req.allowPackage}</if> \n"
            +"</script>")
    IPage<HotelListManagerDTO> queryHotelList(@Param("req") HotelListManagerReq req, IPage<HotelListManagerDTO> agentPage);

    /**
     * 代理商详情查询
     *
     * @param req 入参
     * @return
     */
    @Select("<script>"+"select t_hotel.id,t_hotel.name,t_hotel.brand_name,t_hotel.city_name,t_hotel.location,t_hotel.telephone,t_hotel.source_type from t_hotel WHERE 1 = 1\n" +
            "<if test=\"req.cityName != null and req.cityName != ''\"> and (t_hotel.city_name LIKE CONCAT('%',#{req.cityName},'%'))</if> \n" +
            "<if test=\"req.brandName != null and req.brandName != ''\"> and (t_hotel.brand_name LIKE CONCAT('%',#{req.brandName},'%'))</if> \n" +
            "<if test=\"req.name != null and req.name != ''\"> and (t_hotel.name LIKE CONCAT('%',#{req.name},'%'))</if> \n" +
            "<if test=\"req.sourceType != null and req.sourceType != 0\"> AND t_hotel.source_type = #{req.sourceType}</if> \n" +
            "ORDER BY t_hotel.gmt_create DESC"+"</script>")
    IPage<HotelQueryDTO> queryAllHotelList(@Param("req") HotelQueryReq req, IPage<HotelQueryDTO> hotelPage);
}
